package org.eenie.cartoonist.ui.movie;

import org.eenie.cartoonist.api.movie.MovieEntryApi;
import org.eenie.cartoonist.model.MovieEntryEntity;
import org.eenie.cartoonist.utils.LogUtil;

import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Eenie on 2016/8/17 16:42.
 * Des：给MovieEntry提供数据
 */

public class MovieEntryPresenter {
    private MovieEntryApi mApi;
    private MovieEntryView mView;

    public MovieEntryPresenter(MovieEntryView view) {
        mApi = new MovieEntryApi();
        this.mView = view;
    }

    /**
     *
     * @param id
     */
    public void fetMovieEntry(String id) {
        mApi.fetMovieEntryById(id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<MovieEntryEntity>() {
            @Override
            public void onCompleted() {
                LogUtil.e("load complete");
            }

            @Override
            public void onError(Throwable e) {
                mView.error(e.getMessage());
            }

            @Override
            public void onNext(MovieEntryEntity entity) {
                mView.displayMovieEntry(entity);
            }
        });
    }


}
